package com.singfan.common.db.config;

import com.singfan.common.SingFanException;

/**
 * 数据库的配置信息
 * Author: HanSongHe
 * Date: 15-7-14 上午11:35
 */
public class Database {
    public Database(String id, String type, String dbname, String host, String port, String user, String password, boolean read, boolean write, int initialPoolSize, int minPoolSize, int maxPoolSize){
        this.id = id;
        this.type = type;
        this.dbname = dbname;
        this.host = host;
        this.port = port;
        this.user = user;
        this.password = password;
        this.read = read;
        this.write = write;
        this.initialPoolSize = initialPoolSize;
        this.minPoolSize = minPoolSize;
        this.maxPoolSize = maxPoolSize;

        if(type.toUpperCase().equals(DataBaseType.MYSQL.getValue())){
            dbDriverClass = "com.mysql.jdbc.Driver";
            dbUrl = String.format("jdbc:mysql://%1$s:%2$s/%3$s?useUnicode=true&characterEncoding=utf8", host, port, dbname);
        }
        else {
            throw new SingFanException(String.format("Database.Database() error: Unknown database type(%s) !", type));
        }
    }

    private String id;
    private String type;
    private String dbname;
    private String host;
    private String port;
    private String user;
    private String password;
    private boolean read;
    private boolean write;
    private int initialPoolSize;
    private int minPoolSize;
    private int maxPoolSize;
    private String dbDriverClass = null;
    private String dbUrl = null;

    public String getId() {
        return id;
    }

    public String getType() {
        return type;
    }

    public String getDbname() {
        return dbname;
    }

    public String getHost() {
        return host;
    }

    public String getPort() {
        return port;
    }

    public String getUser() {
        return user;
    }

    public String getPassword() {
        return password;
    }

    public boolean isRead() {
        return read;
    }

    public void setRead(boolean read) {
        this.read = read;
    }

    public boolean isWrite() {
        return write;
    }

    public void setWrite(boolean write) {
        this.write = write;
    }

    public int getInitialPoolSize() {
        return initialPoolSize;
    }

    public int getMinPoolSize() {
        return minPoolSize;
    }

    public int getMaxPoolSize() {
        return maxPoolSize;
    }

    public String getDbDriverClass() {
        return dbDriverClass;
    }

    public String getDbUrl() {
        return dbUrl;
    }
}
